 /*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androcr.client.mobile.display.translator;


import androcr.client.mobile.R;
import androcr.client.mobile.services.translator.ITranslatorPresenter;
import androcr.client.mobile.services.translator.TranslatorPresenter;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;


public class TranslatorActivity extends Activity implements ITranslatorActivity{
    private static final String TAG = "TranslatorActivity";

    private ITranslatorPresenter translatorPresenter;
    private Button buttonTranslate;
    private EditText editTextInputText;
    private EditText editTextOutputText;
    
    private Spinner spinnerFromLang;
    private Spinner spinnerToLang;
   
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.translator);

        translatorPresenter = (ITranslatorPresenter) new TranslatorPresenter(this);
        
        buttonTranslate = (Button) findViewById(R.id.buttonTranslate);
        buttonTranslate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	translatorPresenter.translateString(getDisplayedTextToTranslate().toString());
            }
        });
        
        editTextInputText = (EditText) findViewById(R.id.editTextRecognizedText);
        editTextOutputText = (EditText) findViewById(R.id.editTextOutputText);
        setDisplayedTextToRead(translatorPresenter.getTextToTranslate());
        Log.e(TAG, "translator: " + translatorPresenter.getTextToTranslate());
        
        spinnerFromLang = (Spinner) findViewById(R.id.spinnerFromLang);
        spinnerToLang = (Spinner) findViewById(R.id.spinnerToLang);
        translatorPresenter.fillSpinnersWithLanguages();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    
    @Override
    public void onPause(){
    	super.onPause();
    }
    
    @Override
    public void onResume(){
    	super.onResume();
    }

	@Override
	public CharSequence getDisplayedTextToTranslate() {
		return editTextInputText.getText();
	}

	@Override
	public void setDisplayedTextToRead(CharSequence charSequence) {
		editTextInputText.setText(charSequence);
	}

	@Override
	public EditText getEditTextInputText() {
		return editTextInputText;
	}

	@Override
	public void setEditTextInputText(String text) {
		this.editTextInputText.setText(text);
	}

	@Override
	public EditText getEditTextOutputText() {
		return editTextOutputText;
	}

	@Override
	public void setEditTextOutputText(String text) {
		this.editTextOutputText.setText(text);
	}

	@Override
	public Spinner getSpinnerFromLang() {
		return spinnerFromLang;
	}

	@Override
	public Spinner getSpinnerToLang() {
		return spinnerToLang;
	}

}
